home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / p_man / cat3 / Net::servent.Z / Net::servent
Encoding:
Text File  |  1998-10-28  |  3.7 KB  |  133 lines

  1.  
  2.  
  3.  
  4.      NNNNeeeetttt::::::::sssseeeerrrrvvvveeeennnntttt((((3333)))) 22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))  NNNNeeeetttt::::::::sssseeeerrrrvvvveeeennnntttt((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       Net::servent - by-name interface to Perl's built-in
  10.       getserv*() functions
  11.  
  12.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.        use Net::servent;
  14.        $s =    getservbyname(shift || 'ftp') || die "no service";
  15.        printf "port    for %s is %s, aliases are %s\n",
  16.           $s->name,    $s->port, "@{$s->aliases}";
  17.  
  18.        use Net::servent qw(:FIELDS);
  19.        getservbyname(shift || 'ftp') || die    "no service";
  20.        print "port for $s_name is $s_port, aliases are @s_aliases\n";
  21.  
  22.  
  23.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  24.       This module's    default    exports    override the core
  25.       _g_e_t_s_e_r_v_e_n_t(),    _g_e_t_s_e_r_v_b_y_n_a_m_e(), and _g_e_t_n_e_t_b_y_p_o_r_t() functions,
  26.       replacing them with versions that return "Net::servent"
  27.       objects.  They take default second arguments of "tcp".  This
  28.       object has methods that return the similarly named structure
  29.       field    name from the C's servent structure from _n_e_t_d_b._h;
  30.       namely name, aliases,    port, and proto.  The aliases method
  31.       returns an array reference, the rest scalars.
  32.  
  33.       You may also import all the structure    fields directly    into
  34.       your namespace as regular variables using the    :FIELDS    import
  35.       tag.    (Note that this    still overrides    your core functions.)
  36.       Access these fields as variables named with a    preceding n_.
  37.       Thus,    $serv_obj->name() corresponds to $s_name if you    import
  38.       the fields.  Array references    are available as regular array
  39.       variables, so    for example @{ $serv_obj->aliases() } would be
  40.       simply @s_aliases.
  41.  
  42.       The _g_e_t_s_e_r_v()    function is a simple front-end that forwards a
  43.       numeric argument to _g_e_t_s_e_r_v_b_y_p_o_r_t(), and the rest to
  44.       _g_e_t_s_e_r_v_b_y_n_a_m_e().
  45.  
  46.       To access this functionality without the core    overrides,
  47.       pass the use an empty    import list, and then access function
  48.       functions with their full qualified names.  On the other
  49.       hand,    the built-ins are still    available via the CORE::
  50.       pseudo-package.
  51.  
  52.      EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  53.        use Net::servent qw(:FIELDS);
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      NNNNeeeetttt::::::::sssseeeerrrrvvvveeeennnntttt((((3333)))) 22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))  NNNNeeeetttt::::::::sssseeeerrrrvvvveeeennnntttt((((3333))))
  71.  
  72.  
  73.  
  74.        while (@ARGV) {
  75.            my ($service, $proto) = ((split m!/!, shift), 'tcp');
  76.            my $valet = getserv($service, $proto);
  77.            unless ($valet) {
  78.            warn    "$0: No    service: $service/$proto\n"
  79.            next;
  80.            }
  81.            printf "service $service/$proto is port %d\n", $valet->port;
  82.            print "alias are    @s_aliases\n" if @s_aliases;
  83.        }
  84.  
  85.  
  86.      NNNNOOOOTTTTEEEE
  87.       While    this class is currently    implemented using the
  88.       Class::Struct    module to build    a struct-like class, you
  89.       shouldn't rely upon this.
  90.  
  91.      AAAAUUUUTTTTHHHHOOOORRRR
  92.       Tom Christiansen
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.